<html>
    <head>
    <link rel="stylesheet" href="lmm.css" type="text/css" />
    </head>
<body class="lmm">
<!-- This file is part of the Lisp Machine Manual.  -*-Text-*- -->
<!-- Function Description: Other Predicates. -->

	The following functions are some other general purpose predicates.

<div class='defun'><font class='exdent'><font class='funcname'>eq <font class='italic' color='purple'>x y</font></font></font><br>
<font class="lisp">(eq <font class="italic">x y</font>) =&gt; t</font> if and only if <font class="italic">x</font> and <font class="italic">y</font> are the same object.
It should be noted that things that print the same are not necessarily <font class="lisp">eq</font> to each other.
In particular, numbers with the same value
need not be <font class="lisp">eq</font>, and two similar lists are usually not <font class="lisp">eq</font>.
<p class='cindent'><!-- "eq versus equal" -->
<pre class="lisp">
<font class='exdent'>Examples:</font><!-- exdent -->
(eq 'a 'b) =&gt; nil
(eq 'a 'a) =&gt; t
(eq (cons 'a 'b) (cons 'a 'b)) =&gt; nil
(setq x '(a . b)) (eq x x) =&gt; t
</pre>
Note that in Lisp Machine Lisp equal fixnums are <font class="lisp">eq</font>; this is not true in Maclisp.
Equality does not imply <font class="lisp">eq</font>-ness for other types of numbers.
</div>

<div class='defmac'><font class='exdent'><font class='funcname' id='neq x y'>neq x y</font><font class="italic"> Macro</font><br></font><!-- end font_exdent --><br><font class="lisp">(neq <font class="italic">x y</font>)</font> = <font class="lisp">(not (eq <font class="italic">x y</font>))</font>.  This is provided
simply as an abbreviation for typing convenience.
</div>

<div class='defun'><font class='exdent'><font class='funcname'>equal <font class='italic' color='purple'>x y</font></font></font><br>
The <font class="lisp">equal</font> predicate returns <font class="lisp">t</font> if its arguments are similar
(isomorphic) objects. (cf. <font class="lisp">eq</font>)
<p class='cindent'><!-- "eq versus equal" -->
Two numbers are <font class="lisp">equal</font> if they have the same value (a flonum
is never <font class="lisp">equal</font> to a fixnum though).
Two strings are <font class="lisp">equal</font> if they have the same length,
and the characters composing them are the same.  Alphabetic case is ignored.
For conses, <font class="lisp">equal</font> is defined recursively as
the two <font class="lisp">car</font>'s being <font class="lisp">equal</font> and the two <font class="lisp">cdr</font>'s being equal.
All other objects are <font class="lisp">equal</font> if and only if they are <font class="lisp">eq</font>.
Thus <font class="lisp">equal</font> could have been defined by:
<pre class="lisp">
(defun equal (x y)
       (or (eq x y)
	   (and (numberp x) (numberp y) (= x y))
	   (and (stringp x) (stringp y) (string-equal x y))
	   (and (listp x)
		(listp y)
		(equal (car x) (car y))
		(equal (cdr x) (cdr y))))) 
</pre>

As a consequence of the above definition, it can be seen that
<font class="lisp">equal</font> need not terminate when applied to looped list structure. 
In addition, <font class="lisp">eq</font> always implies <font class="lisp">equal</font>; that is, if <font class="lisp">(eq a b)</font>
then <font class="lisp">(equal a b)</font>.  An intuitive definition of <font class="lisp">equal</font> (which is
not quite correct) is that two objects are <font class="lisp">equal</font> if they look the
same when printed out.  For example:
<pre class="lisp">
(setq a '(1 2 3))
(setq b '(1 2 3))
(eq a b) =&gt; nil
(equal a b) =&gt; t
(equal "Foo" "foo") =&gt; t
</pre>
</div>

<div class='defun'><font class='exdent'><font class='funcname'>not <font class='italic' color='purple'>x</font></font></font><br>
.defun1 null x
	<font class="lisp">not</font> returns <font class="lisp">t</font> if <font class="italic">x</font> is <font class="lisp">nil</font>, else <font class="lisp">nil</font>.
<font class="lisp">null</font> is the same as <font class="lisp">not</font>; both functions are included for the sake
of clarity.  Use <font class="lisp">null</font> to check whether something is <font class="lisp">nil</font>; use <font class="lisp">not</font>
to invert the sense of a logical value.  Even though Lisp uses the symbol
<font class="lisp">nil</font> to represent falseness, you shouldn't make understanding of your program
depend on this fortuitously.  For example, one often writes:
<pre class="lisp">
(cond ((not (null lst)) ... )
      ( ... ))
<font class="main">rather than</font>
(cond (lst ... )
      ( ... ))
</pre>
	There is no loss of efficiency, since these will compile into exactly
the same instructions.
</div>
.eof
</body>
</html>

